import java.util.Vector;
import java.io.BufferedReader;

class SmallTalkClass {
    String name;
    String type;
    String superclass;
    String[] instanceVariables;
    String[] classVariables;
    SymbolDictionary classVariableDictionary;
    
    Vector<SmallTalkMethod> classMethods = new Vector<SmallTalkMethod>();
    Vector<SmallTalkMethod> instanceMethods = new Vector<SmallTalkMethod>();
    
    public SmallTalkClass(BufferedReader reader) throws Exception{
        name = reader.readLine().trim();
        reader.readLine();	//Existing class type:
        type = reader.readLine().trim();
        reader.readLine();	//superclass
        superclass = reader.readLine().trim();
        reader.readLine();	//Named instance variables:
        instanceVariables = reader.readLine().trim().split("[ ]+");
        reader.readLine();	//Class variables:
        classVariables = reader.readLine().trim().split("[ ]+");
        classVariableDictionary = new SymbolDictionary(reader);
        
        String nextLine = reader.readLine().trim();
        
        while(!nextLine.equals("Existing class name:") && !nextLine.equals("End of input")) {
            if(nextLine.equals("Additional instance method:"))
                instanceMethods.add(new SmallTalkMethod(name, reader));
            else if(nextLine.equals("Additional class method:"))
                classMethods.add(new SmallTalkMethod(name, reader));
            nextLine = reader.readLine().trim();
        }
        if(nextLine.equals("End of input"))
            SmallTalkClass.done = true;
    }
    
    public String asString() {
        String ret = "Existing class name:\n" + name;
        ret = ret + "\nExisting class type:\n" + type;
        ret = ret + "\nSuperclass:\n" + superclass;
        ret = ret + "\nNamed instance variables:\n";
        for(String s: instanceVariables)
            ret = ret + s + " ";
        ret = ret + "\nClass variables:\n";
        for(String s: classVariables)
            ret = ret + s + " ";
        ret = ret + "\n";
        ret = ret + classVariableDictionary.asString("Class variable dictionary");
        return ret;
    }
    
    static boolean done = false;
    static SmallTalkClass[] readAll(BufferedReader reader) throws Exception {
        Vector<SmallTalkClass> classes = new Vector<SmallTalkClass>();
        reader.readLine();  //Existing class name:
        
        while(!done)
            classes.add(new SmallTalkClass(reader));
        
        return classes.toArray(new SmallTalkClass[0]);
    }
}
